package com.dpfmanage.api.project.dpfmanage.util.orderlyuuid;


import java.net.InetAddress;
import java.net.UnknownHostException;

public abstract class AbstractUUIDGenerator {
    /**
     * 本机ip
     */
    private static final int IP;
    private static short counter = (short) 0;

    static {
        int ipadd;
        try {
            ipadd = TConverter.toInt(InetAddress.getLocalHost().getAddress());
        } catch (UnknownHostException e) {
            ipadd = 0;
        }
        IP = ipadd;
    }

    public AbstractUUIDGenerator() {
    }

    protected static int getJVM() {
        return (int) (System.currentTimeMillis() >>> 8);
    }

    protected static short getCount() {
        synchronized (AbstractUUIDGenerator.class) {
            if (counter < 0) {
                counter = 0;
            }
            return counter++;
        }
    }

    protected static int getIP() {
        return IP;
    }

    protected static short getHiTime() {
        return (short) (System.currentTimeMillis() >>> 32);
    }

    protected static int getLoTime() {
        return (int) System.currentTimeMillis();
    }
}
